package cn.lf.android.lawfirm.worklog.controller;


import android.content.Context;
import android.util.Pair;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.lf.android.lawfirm.AppConfig;
import cn.lf.android.lawfirm.BaseController;
import cn.lf.android.lawfirm.http.manager.EBCallback;
import cn.lf.android.lawfirm.http.manager.MyOkHttpClient;
import cn.lf.android.lawfirm.utils.DebugLog;
import cn.lf.android.lawfirm.utils.SPUtil;

/**
 * 添加
 */
public class DeleteAgreementConroller extends BaseController {
    DeleteAgreementCallback mDeleteAgreementCallback;
    private Context context;

    public DeleteAgreementConroller(DeleteAgreementCallback callback, Context context) {
        this.mDeleteAgreementCallback = callback;
        this.context = context;
    }


    /**
     * @param fileID
     */
    public void onDeleteAgreement(String fileID) {
        showProgressDia(context);
        Map<String, String> params = new HashMap<String, String>();
        SPUtil spUtil = new SPUtil(context);
        params.put("fileID", fileID);
        DebugLog.e("fileID===" + fileID);
        new MyOkHttpClient().doPost(AppConfig.LsysLog_DelLogFile, params,
                new EBCallback() {
                    @Override
                    public void onEBResponse(String response) {
                        DebugLog.e("删除日志文件===" + response);
                        JSONObject myJsonObject;
                        Boolean isSuc;
                        try {
                            myJsonObject = new JSONObject(response);
                            isSuc = myJsonObject.getBoolean("isSuc");
                            if (isSuc) {
                                mDeleteAgreementCallback.onDeleteAgreementSuccessed("");
                            } else {
                                mDeleteAgreementCallback
                                        .onDeleteAgreementFailed();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        dismissProgressDia();
                    }

                    @Override
                    public void onEBError(String errorMsg) {
                        DebugLog.e("删除日志文件失败===" + errorMsg);
                        mDeleteAgreementCallback.onDeleteAgreementFailed();
                        dismissProgressDia();
                    }
                }, "Authorization", spUtil.getAccessToken());
    }


    public interface DeleteAgreementCallback {
        public void onDeleteAgreementSuccessed(String str);

        public void onDeleteAgreementFailed();

    }

}
